﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using tracker.Models.DTO;
using System.Data;

namespace tracker.Models.DAL
{
    public class DeviceTypeDAL : ErpCatalogueBaseBL
    {
        #region Properties Define
        private string FIELD_DEVICETYPEID = "DeviceTypeID";
        private string FIELD_STATUS = "Status";
        private string FIELD_DEVICEKEYSECURITY = "DeviceKeySecurity";
        #endregion

        #region STORE NAME
        public const string DEVICETYPE_SELECTBYID = "DeviceType_SelectByID";
        public const string DEVICETYPE_SELECTALLBYSTATUS = "DeviceType_SelectAllByStatus";
        public const string DEVICE_SELECTBYDEVICEKEYSECURITY = "Device_SelectByDeviceKeySecurity";
        #endregion

        public  EDeviceType getByID(int id)
        {
            EDeviceType dvt = null;
            DataSet ds = ErpCatalogueBaseBL.SelectAllWithParameter(DEVICETYPE_SELECTBYID,
                                                                  new string[] { FIELD_DEVICETYPEID },
                                                                  new object[] { id });
           
            if (ds.Tables.Count >0)
            {
                DataTable dt = ds.Tables[0];
                dvt = EDeviceType.create(dt.Rows[0]);
            }
            return dvt;
        }
        public  List<EDeviceType> getByStatus(int status)
        {
            List<EDeviceType> list = null;
            DataSet ds = ErpCatalogueBaseBL.SelectAllWithParameter(DEVICETYPE_SELECTALLBYSTATUS,
                                                                   new string[] { FIELD_STATUS },
                                                                   new object[] { status });
            
            if (Utilities.hasRow(ds))
            {
                DataTable dt = ds.Tables[0];
                list = new List<EDeviceType>();
                for (int i = 0; i < dt.Rows.Count; i++)                {
                    EDeviceType dvt = EDeviceType.create(dt.Rows[i]);
                    list.Add(dvt);
                }
            }            
            return list;
        }
    }
}